package com.example.ex_widget;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Ex_ListView extends AppCompatActivity {

    private String[] weekStrings={"星期天","星期一","星期二","星期三","星期四","星期五","星期六",};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ex__list_view);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
            Ex_ListView.this,android.R.layout.simple_list_item_1,weekStrings
    );

    ListView listView = (ListView) findViewById ( R.id.listview );
    listView.setAdapter ( adapter );

    listView.setOnItemClickListener ( new AdapterView.OnItemClickListener () {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Ex_ListView.this.setTitle(((TextView) view). getText());
        }
    } );

}

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        menu.add(0,1,1, "返回上一页");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        if (item.getItemId()==1){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

}
